/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.struts;

import java.util.Calendar;
import java.util.GregorianCalendar;

/***
 * Convenience class owning some methods for date handling in ActionForms
 */
abstract public class ActionForm extends org.apache.struts.action.ActionForm
{
	public static Integer[] daysOfMonth = new Integer[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
	public static Integer[] months = new Integer[]{1,2,3,4,5,6,7,8,9,10,11,12};
	/**
	 * @deprecated Please use getDaysOfMonth()
	 * @return
	 */
	public Integer[] getDaysofmonth()
	{
		return getDaysOfMonth();
	}
	public Integer[] getDaysOfMonth()
	{
		return daysOfMonth;
	}
	public Integer[] getMonths()
	{
		return months;
	}
	public Integer[] getYears()
	{
	  return getLastYears(100);
	}
	public Integer[] getLastYears(int howmany)
	{
		int year = GregorianCalendar.getInstance().get(Calendar.YEAR);
		Integer[] years = new Integer[howmany];
		for (int i=0; i<howmany; i++)
			years[i]=i+1+year-howmany;
		return years;
	}
	public Integer[] getYearsInverted()
	{
		return getLastYearsInverted(100);
	}
	public Integer[] getLastYearsInverted(int howmany)
	{
		int year = GregorianCalendar.getInstance().get(Calendar.YEAR);
		Integer[] years = new Integer[howmany];
		for (int i=year; -i+year<howmany; i--)
			years[-i+year]=i;
		return years;
	}
	public Integer[] getHours()
	{
		Integer[] hours = new Integer[24];
		for (int i=0; i<24; i++)
			hours[i]=i;
		return hours;
	}
	public Integer[] getMinutes()
	{
		Integer[] minutes = new Integer[60];
		for (int i=0; i<60; i++)
			minutes[i]=i+1;
		return minutes;
	}
}
